<template>
	<view class="pagecon">
		<head-box></head-box>
			<view class="page_mian tab-botton">
				<view class="banner">
					<image src="/static/img/wycy_banner.png" mode="aspectFill"></image>
				</view>
				<view class="quntuanListPage-main-header">
					<div class="quntuanListPage-main-title">我要发布活动</div>
				</view>
				<view class="personalInfor-page-main">
					<view class="personalInfor-page-main-box">
						<view class="_main-item" style="display: none;">
							<view class="_main-item-chunk _main-item-label"><text>挂靠群团</text></view>
							<view class="_main-item-chunk _main-item-val">
								<picker class="_main-item-val-input" @change="changetype" :value="TypeIndex" :range="TypeArr" >
									<view class="uni-input _main-item-val-input-text">
										{{TypeArr[TypeIndex]}}
										<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
									</view>
								</picker>
							</view>
						</view>
						<view class="_main-item" >
							<view class="_main-item-chunk _main-item-label"><text>活动类型</text></view>
							<view class="_main-item-chunk _main-item-val">
								<picker class="_main-item-val-input" @change="changetype1" :value="moveTypeIndex" :range="chooseTypeArr" >
									<view class="uni-input _main-item-val-input-text">
										{{chooseTypeArr[moveTypeIndex]}}
										<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
									</view>
								</picker>
							</view>
						</view>
						<view class="_main-item" >
							<view class="_main-item-chunk _main-item-label"><text>发起方</text></view>
							<view class="_main-item-chunk _main-item-val">
								<input cursorSpacing="10" class="_main-item-val-input" type="text" placeholder="请输入单位或组织名称" v-model="userNickname"/>
								<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
							</view>
						</view>
						<view class="_main-item" >
							<view class="_main-item-chunk _main-item-label"><text>活动标题</text></view>
							<view class="_main-item-chunk _main-item-val">
								<input cursorSpacing="10" class="_main-item-val-input" type="text" placeholder="请输入活动的标题" v-model="title"/>
								<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
							</view>
						</view>
						<view class="_main-item" >
							<view class="_main-item-chunk _main-item-label"><text>参与人数</text></view>
							<view class="_main-item-chunk _main-item-val">
								<input cursorSpacing="10" class="_main-item-val-input" type="text" placeholder="请输入共计参数人数" v-model="movenum"/>
								人
							</view>
						</view>
						<view class="_main-item" >
							<view class="_main-item-chunk _main-item-label"><text>活动日期</text></view>
							<view class="_main-item-chunk _main-item-val"  @tap="dateVisible1=true">
								<input cursorSpacing="10" class="_main-item-val-input" disabled="disabled" maxlength="20" type="text" placeholder="活动日期" v-model="date"/>
								<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
							</view>
						</view>
						<view class="_main-item">
							<view class="_main-item-chunk _main-item-label"><text>活动地点</text></view>
							<view class="_main-item-chunk _main-item-val">
								<input cursorSpacing="10" class="_main-item-val-input" type="text" placeholder="请输入活动详细地址" v-model="moveaddr"/>
							</view>
						</view>
						<w-picker
							:visible.sync="dateVisible1"
							mode="date"
							startYear="2021"
							endYear="2039"
							:value="date"
							:current="false"
							fields="second"
							@confirm="onConfirm($event,'date')"
							@cancel="onCancel"
							:disabled-after="false"
							ref="date"
						></w-picker>
						<view class="_main-item" >
							<view class="_main-item-chunk _main-item-label"><text>手机号码</text></view>
							<view class="_main-item-chunk _main-item-val">
								<input class="_main-item-val-input" maxlength="11" type="text" placeholder="手机号码" v-model="userPhone"/>
								<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
							</view>
						</view>

					</view>
				</view>
				<view>
					<textarea class="textarea" v-model="advice" placeholder="请输入活动的详细描述"></textarea>
				</view>
				<view class="subbtn">
					<button type="primary"  @click="submit">发布活动申请</button>
				</view>
			</view>
		<tabs-box></tabs-box>
	</view>
</template>

<script>
	import { mapState,mapMutations} from 'vuex';
	import { gpUseradvisesubmit,gpGpinfoList,getDictItems} from '@/common/request.js';
	import {goLogin} from '@/common/base'
	export default {
		data() {
			return {
				advice:'',
				userNickname:'',
				userPhone:'',
				date:'',
				moveaddr:'',
				title:'',
				TypeArr:["请选择","群团1","群团2","群团3","群团4","15个群团"],
				TypeArrall:["0","1","2","3","4"],
				TypeIndex: 0,

				chooseTypeArr: ['全部类型'],
				chooseTypeVal: [''],
				moveTypeIndex: 0,

				movenum:0,
				pageSize:20,
				pageNo:1,
				dateVisible1:false,
			};
		},
		computed: {
			...mapState(['hasLogin', 'userInfo','token'])
		},
		onLoad() {
			if(!uni.getStorageSync("token"))
			{
        goLogin()
				//return;
			}

			this.date = this.getDate('start');
			this.GetType();
			//this.getList();
		},
    onShow(){
      // #ifdef H5
      console.log('分享')
      this.$wxSetShare()
      // #endif
    },
		methods: {
			bindDateChange: function(e) {
			            this.date = e.target.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 0;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			submit()
			{


				//if(this.chooseTypeIndex ==0)
				//{
				//	this.$api.msg('请选择目标群团');
				//	return;
				//}
				if(this.moveTypeIndex == 0)
				{
					this.$api.msg('请选择类型');
					return;
				}
				if(this.userNickname.length < 2)
				{
					this.$api.msg('请输入正确的姓名或公司名');
					return;
				}
				if(this.title == '')
				{
					this.$api.msg('活动标题不能为空');
					return;
				}

				if(this.movenum < 5)
				{
					this.$api.msg('参与人数不能为5人');
					return;
				}

				if(this.moveaddr.length < 10)
				{
					this.$api.msg('必须输入详细的活动地址');
					return;
				}


				if(this.date.length < 10)
				{
					this.$api.msg('活动日期错误');
					return;
				}

				if(this.userPhone.length != 11)
				{
					this.$api.msg('手机号码不正确');
					return;
				}

				if(this.advice =='')
				{
					this.$api.msg('活动详情描述不能为空');
					return;
				}

				let message = "活动类型："+this.chooseTypeArr[this.moveTypeIndex];
				message += "\r\n发起单位："+this.userNickname;
				message += "\r\n活动标题："+ this.title;
				message += "\r\n参与人数："+ this.movenum + "人";
				message += "\r\n活动地址："+ this.moveaddr;
				message += "\r\n活动日期："+ this.date;
				message += "\r\n联系电话："+ this.userPhone;
				message += "\r\n活动描述："+ this.advice;


				if(!uni.getStorageSync("token"))
				{
					this.$api.msg('请先登录!!');
					return;
				}
				var params ={"adviseContent": message,"useradviseType":"7"}
				console.log(params);
				gpUseradvisesubmit(params).then(res => {
					console.log(res)

					if(res.success)
					{
						this.$api.msg('提交成功,感谢您的建议');
						this.advice = '';
						setTimeout(() => {
							uni.navigateTo({
								url:'/pages/mySuggestion/mySuggestion'
							})
						}, 1000);
					}
				});
			},
			changetype(e) {
				console.log('picker发送选择改变，携带值为', e.target.value)
				this.TypeIndex = e.target.value
				console.log(this.TypeArrall[this.TypeIndex]);
				//this.GetList()
			},
			changetype1(e) {
				console.log('picker发送选择改变，携带值为', e.target.value)
				this.moveTypeIndex = e.target.value
				console.log(this.moveTypeArrall[this.moveTypeIndex]);
				//this.GetList()
			},
			onConfirm(res,type){
				this.date=res.result;
				console.log(res)
			},
			GetType(){
				var that = this
				let params = {"column": "sorting","order": "desc"}
				getDictItems(params,"move_type").then(res => {
					if(res.success)
					{
						res.result.forEach(ele => {
							that.chooseTypeArr.push(ele.text)
							that.chooseTypeVal.push(ele.value)
						})
					}
				})
			},

		}
	}
</script>

<style lang="scss">
	.pagecon{
		height: 100vh;
		.page_mian{
			padding: 30rpx;
			.banner{
				width: 100%;
				height: 280rpx;
				margin-bottom: 60rpx;
				image{
					width: 100%;
					height: 100%;
					border-radius: 10rpx;
				}
			}

			.quntuanListPage-main-title{
				font-size: 32rpx;
				color: #333;
				font-weight: 600;
				border-left: 6rpx solid #0071fc;
				background-image:linear-gradient(left, #eff6ff, #ffffff);
				padding-left: 20rpx;
			}

			.textarea{
				border-radius: 10rpx;
				border: 1px solid #cccccc;
				padding: 20rpx;
				width: calc(100% - 40rpx) ;
				margin-top: 50rpx;
			}
			.subbtn{
				margin-top: 50rpx;
			}
		}

		.personalInfor-page-main{
			width: 100%;
			box-sizing: border-box;
			margin-top: 40rpx;
			.personalInfor-page-main-box{
				width: 100%;
				._main-item{
					// height: 86rpx;
					border-bottom: 1px solid rgba(200,199,204,0.5);
					display: flex;
					flex-wrap: nowrap;
					justify-content: space-between;
					align-items: center;
					._main-item-chunk{
						font-size: 34rpx;
						color: #000;
						line-height: 84rpx;
					}
					._main-item-label{
						width: 30%;
					}
					._main-item-val{
						width: 70%;
						display: flex;
						flex-wrap: nowrap;
						justify-content: flex-end;
						align-items: center;
						._main-item-val-head{
							width: 48rpx;
							height: 48rpx;
							border-radius: 50%;
							display: flex;
							.head-img{
								width: 100%;
								height: 100%;
								border-radius: 50%;
							}
						}
						._main-item-val-input{
							text-align: right;
							display: flex;
							._main-item-val-input-text{
								display: flex;
								flex-wrap: nowrap;
								align-items: center;
							}
							.drop-dowm-img{
								width: 30rpx;
								height: 30rpx;
								margin-left: 10rpx;
								transform: rotateZ(270deg);
							}
						}
						.drop-dowm-img{
							width: 30rpx;
							height: 30rpx;
							margin-left: 10rpx;
							transform: rotateZ(270deg);
						}
					}
				}

			}
		}
	}
</style>
